package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.entity.InHospital;
import com.qianfeng.entity.Registration;
import com.qianfeng.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.Map;

@Controller
public class InHospitalController {
    @Autowired
    private MoneyHelperService moneyHelperService;
    @Autowired
    private InHospitalService inHospitalService;
    @Autowired
    private RegistrationService registrationService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private DepartmentService departmentService;
    @RequestMapping("/getInHospitalList")
    public String getInHospitalList(){
        return "03_in_the_hospital_for";
    }

    @ResponseBody
    @RequestMapping("/getRegistrationById")
    public Registration getRegistrationById(Integer rId){
        return registrationService.getRegistrationById(rId);
    }
    @ResponseBody
    @RequestMapping("/getInHospitalPage")
    public Page getInHospitalPage(Integer pageNo, Integer pageSize){
        int pageNo_=1;
        int pageSize_=2;
        if (pageNo!=null){
            pageNo_=pageNo;
        }
        if (pageSize!=null){
            pageSize_=pageSize;
        }
        Page page = inHospitalService.getInHospitalPage(pageNo_, pageSize_);
        return page;
    }
    @RequestMapping("/getInHospitalDetail")
    public String getInHospitalDetail(Integer ihId, Map map){
        InHospital inHospital = inHospitalService.getInHospitalById(ihId);
        map.put("inHospital",inHospital);
        //System.out.println(inHospital);
        return "03_03_in_the_hospital_detail";
    }
    @RequestMapping("/tuiHospital")
    public String tuiHospital(Integer ihId){
        InHospital inHospital = inHospitalService.getInHospitalById(ihId);
        Registration registration = registrationService.getRegistrationById(inHospital.getrId());
        registration.setrStatus(3);
        registrationService.updateRegistration(registration);
        return "03_in_the_hospital_for";
    }
    @RequestMapping("/chuHospital")
    public String chuHospital(Integer ihId){
        InHospital inHospital = inHospitalService.getInHospitalById(ihId);
        Registration registration = registrationService.getRegistrationById(inHospital.getrId());
        registration.setrStatus(2);
        registrationService.updateRegistration(registration);
        return "03_in_the_hospital_for";
    }

    @RequestMapping("/jumpAddDeposit")
    public String jumpAddDeposit(Integer ihId,Map map){
        InHospital inHospital = inHospitalService.getInHospitalById(ihId);
        map.put("inHospital",inHospital);
        return "03_04_in_the_hospital_adddeposit";
    }

    @RequestMapping("/addDeposit")
    public String addDeposit(Integer ihId,Double money){

        System.out.println("addDeposit==================");
        System.out.println(ihId);
        System.out.println(money);

        inHospitalService.addInHospitalMoney(ihId,money);
        return "03_in_the_hospital_for";
    }

    @RequestMapping("/jumpAddInHospital")
    public String jumpAddInHospital(){
        return "03_01_in_the_hospital_add";
    }

    @RequestMapping("/addInHospital")
    public String addInHospital(InHospital inHospital){
        inHospital.setIhTime(new Date());
        inHospitalService.addInHospital(inHospital);
        return "03_in_the_hospital_for";
    }
    @RequestMapping("/jumpUpdateInHospital")
    public String jumpUpdateInHospital(Integer ihId,Map map){
        InHospital inHospital = inHospitalService.getInHospitalById(ihId);
        map.put("inHospital",inHospital);
        return "03_02_in_the_hospital_update";
    }
    @RequestMapping("/updateInHospital")
    public String updateInHospital(InHospital inHospital){
        inHospitalService.updateInHospital(inHospital);
        return "03_in_the_hospital_for";
    }

    @RequestMapping("/InHospitalAccount")
    public String InHospitalAccount(){
        return "04_in_the_hospital_and_settlement";
    }

    @ResponseBody
    @RequestMapping("/InHospitalAccountPage")
    public Page InHospitalAccountPage(Integer pageNo,Integer pageSize){
        int pageNo_=1;
        int pageSize_=2;
        if (pageNo!=null){
            pageNo_=pageNo;
        }
        if (pageSize!=null){
            pageSize_=pageSize;
        }
        Page page = moneyHelperService.getMoneyHelperPage(pageNo_, pageSize_);
        return page;
    }

    @RequestMapping("/InHospitalJieSuan")
    public String InHospitalJieSuan(Integer rId){
        InHospital inHospital = inHospitalService.getInHospitalByRegistrationId(rId);
        inHospital.setIhStatus(1);
        inHospitalService.updateInHospital(inHospital);
        return "04_in_the_hospital_and_settlement";
    }



}
